package com.lixin.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class Ticket {

    private int ticketNum = 10000;

    Lock lock = new ReentrantLock();

    public void sale() {
        lock.lock();
        try {
            if (ticketNum > 0) {
                ticketNum--;
                System.out.println(Thread.currentThread().getName() + " 还剩" + ticketNum + "张票");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

}
